package com.qf.controller;

import com.qf.enums.UserEnum;
import com.qf.exception.UserException;
import com.qf.service.ShpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/shopping")
public class ShoppingController {
    @Autowired
    ShpService shpService;

    @GetMapping("/goShopping")
    public String goShopping(Integer goodsId, Integer goodsCount){
//        这里后端的参数校验省略
        System.out.println(goodsId+"====="+goodsCount);
        Integer countParam = shpService.saveShopping(goodsId, goodsCount);
        if (countParam!=1){
            throw new UserException(UserEnum.PATAMS_ERROR.getCode(),"保存订单失败");
        }
        return "cart";
    }
}
